package 剑指offer;

public class Offer04_JZ01 {
    public static void main(String[] args) {
        int[][] arr = new int[][]{
                {1,2,8,9},
                {2,4,9,12},
                {4,7,10,13},
                {6,8,11,15}
        };

        System.out.println(Find(7, arr));
    }

    public static boolean Find(int target, int [][] array) {
        int row_len = array[0].length;
        int col_len = array.length;
        int i=0, j=col_len-1;
        while (j>=0 && i<row_len) {
            if (target == array[i][j]) {
                return true;
            } else if(target < array[i][j]) {
                j--;
            } else {
                i++;
            }
        }
        return false;
    }
}
